使用ggmap绘制物种分布区图:

source("D:/HIDATA/项目代码xmind管理/share_code/sdmenm.R")
aocc <- rbind(xh_as,ch_as) %>% data.frame()
range1 <- frange(aocc)
e = extent(range1)
buf = .5
chuck.df<- as.data.frame(range1)

library(ggmap)
myMap <- get_stamenmap(bbox = c(left = e[1]-buf,
                                bottom = e[3] -buf,
                                right = e[2]+buf,
                                top = e[4] +buf),
                       maptype = "terrain",
                       crop = FALSE,
                       zoom = 6)

aocc2 <- c(rep("xh",dim(xh_as)[1]),rep("ch",dim(ch_as)[1])) %>% cbind(aocc) %>% data.frame()
names(aocc2) <- c("name","lon","lat")
attach(aocc2)
aocc2$name <- factor(aocc2$name)
dev.off()
ggmap(myMap) +  geom_point(aes(x = lon, y = lat,colour= name), data = aocc2,alpha = .5,size=2)

使用tmap包可视化物种分布:

library(sf)
library(tmap)

occ_data <- st_as_sf(xh_as, coords = c("longitude", "latitude"), crs = CRS("+init=epsg:4326"))
names(saxh) <- "probability"
t1 <- saxh %>%  ## 这里的saxh是投影的栅格;
  tm_shape(raster.downsample= F) + 
  tm_raster(legend.show = F, palette=rev(terrain.colors(5)),n=5,style="cont",stretch.palette =T)+

  tm_legend(position=c("right","bottom"), scale=1.3,frame=FALSE,legend.text.color ="white")+
  tm_layout(legend.width =2)+
  # tm_shape(occ_data)+
  # tm_symbols(col = "#698B69",alpha=0.5, scale = .5,size=0.5,border.alpha = 0.3,border.lwd = 0.3) +
  # tm_scale_bar(position=c("left","bottom"),text.size = 0.8) +
  #添加指北针
  # tm_compass(type = "arrow", position=c("left", "bottom"),size=5) +
  tm_xlab("",size = 1) +
  tm_ylab("",size = 1)


tmap_arrange(t1, t2,t3,t4,t5,t6,t7,t8,ncol = 2,nrow=4, outer.margins = 0.02)

## 另外一种:
library(maptools)
data(wrld_simpl)
pcaxh %>% 
  tm_shape() + 
  tm_raster(legend.show = TRUE,palette=rev(terrain.colors(10)),
            title = "SUITABLE")+
  tm_legend(position=c("left","bottom"), frame=FALSE)+
  tm_shape(wrld_simpl)+
  tm_borders(col="gray50",alpha = 0.6)+
  tm_xlab("Longitude",size = 1) +
  tm_ylab("Latitude",size = 1)+
  tm_graticules(ticks = TRUE,lines=FALSE)

results matching ""

    No results matching ""